﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace WpfApp1.Command
{
    class DoCommand : ICommand
    {
        public event EventHandler? CanExecuteChanged;
        /// <summary>
        /// 要执行的事情
        /// </summary>
        private Action _action;
        public DoCommand(Action action) 
        {
            _action=action;
        }
        /// <summary>
        /// 能否执行
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public bool CanExecute(object? parameter)
        {
            return true;
        }
        /// <summary>
        /// 执行的事情
        /// </summary>
        /// <param name="parameter"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void Execute(object? parameter)
        {

            if (_action != null)
            {
                _action();
            }
        } 
    }
}
